package com.htgd.gardenexpo.controller;


import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConFoodShop;
import com.htgd.gardenexpo.entity.GeConFunSports;
import com.htgd.gardenexpo.page.FoodShopQuery;
import com.htgd.gardenexpo.page.FunSportsQuery;
import com.htgd.gardenexpo.service.IGeConFunSportsService;
import com.htgd.gardenexpo.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 趣运动表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-04-14
 */
@RestController
@RequestMapping("/api/funSports")
@Api(tags = "趣运动")
@Slf4j
public class GeConFunSportsController {

    @Autowired
    private IGeConFunSportsService geConFunSportsService;

    @PostMapping("/add")
    @ApiOperation("添加")
    public CommonResult add(@RequestBody GeConFunSports geConFunSports){
        log.info("趣运动-添加：{}",geConFunSports);
        return geConFunSportsService.add(geConFunSports);
    }

    @PostMapping("/edit")
    @ApiOperation("编辑")
    public CommonResult edit(@RequestBody GeConFunSports geConFunSports){
        log.info("趣运动-编辑：{}",geConFunSports);
        return geConFunSportsService.edit(geConFunSports);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除")
    public CommonResult delete(@RequestParam(value = "id")String id){
        log.info("趣运动-删除：{}",id);
        return geConFunSportsService.delete(id);
    }

    @GetMapping("/list")
    @ApiOperation("列表查询")
    public CommonResult list(FunSportsQuery funSportsQuery, HttpServletRequest request){
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("趣运动-列表查询：{},{}",openId,funSportsQuery);
        return geConFunSportsService.pageList(openId,funSportsQuery);
    }

    @GetMapping("/details")
    @ApiOperation("详情")
    public CommonResult details(@RequestParam(value = "id")String id,HttpServletRequest request){
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("趣运动-详情：{},{}",openId,id);
        return geConFunSportsService.details(openId,id);
    }

    @GetMapping(value = "/review")
    @ApiOperation("审核")
    public CommonResult review(GeConFunSports geConFunSports) {
        log.info("趣运动-审核：{}",geConFunSports);
        return geConFunSportsService.review(geConFunSports);
    }

}
